package com.example.boke.mapper;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.io.Encoders;
import io.jsonwebtoken.security.Keys;
import org.junit.jupiter.api.Test;

import javax.crypto.SecretKey;
import java.security.Key;
import java.util.HashMap;
import java.util.Map;

public class JwtUtilsTest {
    @Test
    public void genJwt(){
        String secr ="j2nQnkT9x07CBA/l8j3oMOkDjVtrzNtNuEnWv4hUHKo=";
        Key key = Keys.hmacShaKeyFor(Decoders.BASE64.decode(secr));
        Map<String,Object> claim = new HashMap<>();
        claim.put("id",1);
        claim.put("name","zhangsan");

        String token = Jwts.builder().setClaims(claim).signWith(key).compact();
        System.out.println(token);
    }
    @Test
    public void genKey(){
        SecretKey secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS256);
        String str = Encoders.BASE64.encode(secretKey.getEncoded());
        System.out.println(str);
    }
}
